package com.losalpes.security;

import com.losalpes.persistence.entity.TipoUsuario;
import com.losalpes.persistence.entity.Usuario;
import javax.ejb.EJB;

/**
 *
 * @author Camilo Alvarez
 */

public class SecurityBean {
    @EJB
    private ISecurityService securityService;
    private String username;
    private String pwd;

    public SecurityBean() {
        //securityService = new SecurityServiceMock();
    }

    public String login(){
        Usuario user = securityService.login(username, pwd);
        if(user.getTipoUsuario() == TipoUsuario.ADMINISTRADOR){
            return "administrador";
        }else{
            return "cliente";
        }
    }

    public String getPwd() {
        return pwd;
    }

    public void setPwd(String pwd) {
        this.pwd = pwd;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String action()
    {
        if(username == null)
        {
            return "login";
        }
        else
        {
            return "editClient";
        }            
    }

    public String logout()
    {
        username = null;
        pwd = null;
        return "login";
    }



}
